<template>
  <div>
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible" @close="cancal(vs[0])">
      <el-form :model="form">
        <el-form-item label="活动名称" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="活动区域" :label-width="formLabelWidth">
          <el-select v-model="form.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancal(vs[0])">取 消</el-button>
        <el-button type="primary" @click="success(vs[0])">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="收货地址" :visible.sync="dialogVisible" @close="cancal(vs[1])">
      <el-form :model="form">
        <el-form-item label="活动名称" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="活动区域" :label-width="formLabelWidth">
          <el-select v-model="form.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancal(vs[1])">取 消</el-button>
        <el-button type="primary" @click="success(vs[1])">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="上传头像" :visible.sync="dialogImgVisible" @close="cancal(vs[2])">
      <el-upload
        class="avatar-uploader"
        action="/api/user/upload"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload"
        :data="username"
      >
        <img v-if="imageUrl" :src="imageUrl" class="avatar" />
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
    </el-dialog>
    <el-dialog title="修改个人资料" :visible.sync="dialogEditVisible" @close="cancal(vs[3])">
      <el-form :model="form">
        <el-form-item label="真实姓名" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="性别" :label-width="formLabelWidth">
          <el-radio v-model="form.gender" label="0">男</el-radio>
          <el-radio v-model="form.gender" label="1">女</el-radio>
        </el-form-item>
        <el-form-item label="职务" :label-width="formLabelWidth">
          <el-select v-model="form.role" placeholder="请选择活动区域">
            <el-option label="班长" value="班长"></el-option>
            <el-option label="学习委员" value="学习委员"></el-option>
            <el-option label="团支书" value="团支书"></el-option>
            <el-option label="生活委员" value="生活委员"></el-option>
            <el-option label="文娱委员" value="文娱委员"></el-option>
            <el-option label="体育委员" value="体育委员"></el-option>
            <el-option label="副班" value="副班"></el-option>
            <el-option label="志愿队长" value="志愿队长"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生日" :label-width="formLabelWidth">
          <el-date-picker
            v-model="form.birthday"
            type="date"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="银行卡号" :label-width="formLabelWidth">
          <el-input v-model="form.cardNum" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话号码" :label-width="formLabelWidth">
          <el-input v-model="form.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" :label-width="formLabelWidth">
          <el-input v-model="form.email" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancal(vs[3])">取 消</el-button>
        <el-button type="primary" @click="success(vs[3])">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";

export default {
  name: "Lack",
  data() {
    return {
      vs:['visible','find','changeImg','editInfo'],
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: ""
      },
      formLabelWidth: "120px",
      imageUrl: "",
      username:"user"
    };
  },
  computed: {
    ...mapState(["dialogFormVisible", "dialogVisible", "dialogImgVisible","dialogEditVisible"])
  },
  props: ["msg"],
  mounted() {
    this.defa();
  },
  methods: {
    handleAvatarSuccess(res, file) {
      console.log(res.data);
      this.imageUrl = res.data.data;
      //this.$store.dispatch("changeImg", true);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    defa() {
      console.log(this.msg);
      this.form.name = this.msg[0];
    },
    cancal(visible) {
      this.$store.dispatch(visible, true);
    },
    success(visible) {
      this.$store.dispatch(visible, true);
    }
  }
};
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>